#ifndef DISTANCEMATRIX_H
#define DISTANCEMATRIX_H

#include <vector>
#include <iostream>
#include <iomanip>
#include <float.h>

namespace zbp
{
	template <typename T>
	class DistanceMatrix
	{
	public:
		int rows;
		int cols;

		DistanceMatrix() 
		{
			this->rows = 0;
			this->cols = 0;
		};

		DistanceMatrix(int rows, int cols)
		{
			for(int i = 0; i < rows; i++)
			{
				_data.push_back(std::vector<T>());

				for(int j = 0; j < cols; j++)
				{
					if (i != j)
					{
						_data[i].push_back(inf);
					}
					else
					{
						_data[i].push_back(0);
					}
				}
			}

			this->rows = rows;
			this->cols = cols;
		}

		inline std::vector<T> & operator[] (int i) 
		{  
			return _data[i]; 
		}

		inline const std::vector<T> & operator[] (int i) const 
		{ 
			return _data[i]; 
		}

		void add_edges(std::vector<T> edges)
		{
			_data.push_back(edges);
			this->rows++;
			this->cols = edges.size();
		}

		void resize(int new_rows, int new_cols)
		{
			_data.resize(new_rows);
			for(int i = 0; i < rows; i++)
			{
				_data[i].resize(new_cols);

				for (int j = cols; j < new_cols; j++)
				{
					_data[i][j] = inf;
				}
			}

			for(int i = rows; i < new_rows; i++)
			{
				_data[i].resize(new_cols);

				for (int j = 0; j < new_cols; j++)
				{
					if (i != j)
					{
						_data[i][j] = inf;
					}
					else
					{
						_data[i][j] = 0;
					}
				}
			}

			rows = new_rows;
			cols = new_cols;
		}

		void resize()
		{
			resize(rows + 1, cols + 1);
		}

		void display(std::ostream &output = cout)
		{
			output << endl;
			for (int i = 0; i < _data.size(); i++)
			{
				for (int j = 0; j < _data[i].size(); j++)
				{
					if (_data[i][j] == inf)
					{
						output << std::setw(5) << "inf";
					}
					else
					{
						output << std::setw(5) << _data[i][j];
					}
				}

				output << endl;
			}
		}

	private:
		static const int inf = INT_MAX; 

		std::vector<std::vector<T>> _data;  
	};
}

#endif